﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.TcCommands.TcCommandsUtility
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using COMMANDPARAMSLib;
using EngineeringInternalExtension;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.PrivateImplementationDetails;
using Tecnomatix.Planning;


namespace DnProcessSimulateCommands.TcCommands;

public static class TcCommandsUtility
{
  public static bool PromptSaveStudyAndProceed(string saveText, string commandName)
  {
    bool flag = true;
    if (TxEngineeringDataInternal.GlobalSessionIsDatabaseModified())
    {
      switch (TxMessageBox.Show(string.Format(saveText, (object) "\n", (object) TxApplication.ActiveDocument.FinalDestination), commandName, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation))
      {
        case DialogResult.Cancel:
          flag = false;
          break;
        case DialogResult.Yes:
          new TxCommandManager().ExecuteCommandByCommandProgId("EngineeringDataOperations.CCoEDOSaveStudyCmd", (object) null, false);
          flag = !TxEngineeringDataInternal.GlobalSessionIsDatabaseModified();
          break;
        case DialogResult.No:
          flag = true;
          break;
      }
    }
    return flag;
  }

  public static bool PromptUpdateTcAndProceed(string saveText, string commandName)
  {
    bool flag = true;
    if (TxEngineeringDataInternal.GlobalSessionIsDatabaseModified())
    {
      switch (TxMessageBox.Show(saveText, commandName, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation))
      {
        case DialogResult.Cancel:
          flag = false;
          break;
        case DialogResult.Yes:
          TxCommandManager txCommandManager = new TxCommandManager();
          CoExportToTcParams exportToTcParams = (CoExportToTcParams) new CoExportToTcParamsClass();
          ((ICoExportToTCParams) exportToTcParams).SetConfirmSave(0);
          txCommandManager.ExecuteCommandByCommandProgId("TCIntegCommands.CCoExportToTC", (object) exportToTcParams, false);
          flag = !TxEngineeringDataInternal.GlobalSessionIsDatabaseModified();
          break;
        case DialogResult.No:
          flag = true;
          break;
      }
    }
    return flag;
  }

  public static bool PromptSaveOrUpdateTcAndProceed(string saveText, string commandName)
  {
    return !TxTcUtilities.IsTcOfflinePlatform ? TcCommandsUtility.PromptUpdateTcAndProceed(saveText, commandName) : TcCommandsUtility.PromptSaveStudyAndProceed(saveText, commandName);
  }

  public static bool IsEquipment(ITxObject obj)
  {
    bool flag = false;
    if (obj is ITxComponent itxComponent && itxComponent.IsEquipment)
      flag = true;
    return flag;
  }

  public static bool IsLeafComponent(ITxObject obj)
  {
    bool flag = false;
    if (obj is ITxComponent itxComponent)
      flag = !itxComponent.IsSuperComponent;
    return flag;
  }

  public static bool IsUnderEquipment(ITxObject obj)
  {
    bool flag = false;
    if (obj.Collection is ITxComponent collection && collection.IsEquipment)
      flag = true;
    return flag;
  }

  public static bool IsPrototypeAssignment(ITxObject obj)
  {
    bool flag = false;
    if (obj is ITxProcessModelObject processModelObject)
      flag = processModelObject.PlanningRepresentation is TxPlanningPrototypeAssignment;
    return flag;
  }

  public static bool IsInModeling(ITxComponent component)
  {
    bool flag = false;
    try
    {
      flag = component.RepresentationType == 6;
    }
    catch (TxNotImplementedException ex)
    {
    }
    return flag;
  }
}
